package com.han.demo.task;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author hanjl
 * @Description 异步任务
 * @ClassName AsyncTask
 * @createTime 2021/12/2 9:30
 */
@Component
@Slf4j
public class AsyncTask {

    @Async("otherTaskExecutor")
    @SneakyThrows
    public void task1(){
        long t1 = System.currentTimeMillis();
        Thread.sleep(2000);
        long t2 = System.currentTimeMillis();
        log.info("task1 cost {} ms" , t2-t1);
    }

    @Async
    @SneakyThrows
    public void task2(){
        long start = System.currentTimeMillis();
        Thread.sleep(3000);
        long ent = System.currentTimeMillis();
        log.info("task2 cost {} ms",ent - start);
    }

}
